package com.mathdroid.gui.main.browser;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;

import com.mathdroid.model.Model;

/**
 * This ActionListener listens to selections in the item browser menu.
 */
public final class MenuListener implements ActionListener {

	/**
	 * The type of item.
	 */
	private String type = null;
	
	/**
	 * The "head" auf menu structure.
	 */
	private JMenu menu = null;
	
	/**
	 * Create a new MenuListener.
	 * @param t Item type.
	 * @param m "Head" of menu.
	 */
	public MenuListener(final String t, final JMenu m) {
		this.type = t;
		this.menu = m;
	}
	
	@Override
	public void actionPerformed(final ActionEvent e) {
		Model.getProfile().getItemBrowserModel().setTypeCondition(
				this.type);
		this.menu.setText(this.type);
		Model.refreshItemBrowserModel();
	}

}
